themingbackground: Restructure code some more
authorBenjamin Otte <otte@redhat.com>
Fri, 26 Oct 2012 23:39:30 +0000 (01:39 +0200)
committerBenjamin Otte <otte@redhat.com>
Wed, 31 Oct 2012 10:09:11 +0000 (11:09 +0100)
Move variable initialization outside the first code with side effects.
This allows adding some more early returns, including one for code that
used to trigger g_return_if_fail() in certain corner cases.

gtk/gtkthemingbackground.c

index 0453f82327ec6c7c0418daf43b5ed3689eca2bed..bf7a6b51ac69e03d1d3961d3bc951533f84afc37 100644 (file)
@@ -154,16 +154,9 @@ _gtk_theming_background_paint_layer (GtkThemingBackground *bg,
   double image_width, image_height;
   double width, height;
 
-  if (layer->image == NULL
-      || layer->image_rect.width <= 0
-      || layer->image_rect.height <= 0)
+  if (layer->image == NULL)
     return;
 
-  cairo_save (cr);
-
-  _gtk_rounded_box_path (&layer->clip_box, cr);
-  cairo_clip (cr);
-
   pos = _gtk_css_array_value_get_nth (_gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_POSITION), layer->idx);
   repeat = _gtk_css_array_value_get_nth (_gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_REPEAT), layer->idx);
   hrepeat = _gtk_css_background_repeat_value_get_x (repeat);
@@ -171,6 +164,9 @@ _gtk_theming_background_paint_layer (GtkThemingBackground *bg,
   width = layer->image_rect.width;
   height = layer->image_rect.height;
 
+  if (width <= 0 || height <= 0)
+    return;
+
   _gtk_css_bg_size_value_compute_size (_gtk_css_array_value_get_nth (_gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_SIZE), layer->idx),
                                        layer->image,
                                        width,
@@ -178,12 +174,22 @@ _gtk_theming_background_paint_layer (GtkThemingBackground *bg,
                                        &image_width,
                                        &image_height);
 
+  if (image_width <= 0 || image_height <= 0)
+    return;
+
   /* optimization */
   if (image_width == width)
     hrepeat = GTK_CSS_REPEAT_STYLE_NO_REPEAT;
   if (image_height == height)
     vrepeat = GTK_CSS_REPEAT_STYLE_NO_REPEAT;
 
+
+  cairo_save (cr);
+
+  _gtk_rounded_box_path (&layer->clip_box, cr);
+  cairo_clip (cr);
+
+
   cairo_translate (cr, layer->image_rect.x, layer->image_rect.y);
 
   if (hrepeat == GTK_CSS_REPEAT_STYLE_NO_REPEAT && vrepeat == GTK_CSS_REPEAT_STYLE_NO_REPEAT)
@@ -301,6 +307,7 @@ _gtk_theming_background_paint_layer (GtkThemingBackground *bg,
       cairo_fill (cr);
     }
 
+
   cairo_restore (cr);
 }